/**
 * 会员信息展示页面类
 * 业务层级：表示层
 * 功能说明：提供会员信息的完整展示界面，包括会员基本信息、账户信息、等级历史等
 * 架构关系：遵循四层架构设计，调用业务层服务获取数据，为用户提供会员信息查看功能
 */
#ifndef MEMBERINFOPAGE_H
#define MEMBERINFOPAGE_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QScrollArea>
#include <QFrame>
#include <QComboBox>
#include <QLineEdit>
#include <QGroupBox>
#include <QSplitter>
#include "../services/memberservice.h"
#include "../database/database.h"

class MemberInfoPage : public QWidget
{
    Q_OBJECT

public:
    explicit MemberInfoPage(Database *db, QWidget *parent = nullptr);
    ~MemberInfoPage();

private slots:
    void onMemberSelectionChanged(QTableWidgetItem *current, QTableWidgetItem *previous);
    void onRefreshClicked();
    void onSearchTextChanged();

private:
    void initUI();
    void setupMemberListArea();
    void setupMemberDetailArea();
    void setupLevelHistoryArea();
    void applyGreenThemeStyles();
    
    void loadMemberList();
    void loadMemberDetail(int memberId);
    void loadMemberLevelHistory(int memberId);
    void clearMemberDetail();
    void filterMemberList(const QString &searchText);

    // 数据服务
    MemberService *m_memberService;
    Database *m_db;

    // 主布局组件
    QVBoxLayout *m_mainLayout;
    QSplitter *m_mainSplitter;

    // 左侧会员列表区域
    QWidget *m_leftPanel;
    QVBoxLayout *m_leftLayout;
    QGroupBox *m_memberListGroup;
    QLineEdit *m_searchEdit;
    QPushButton *m_refreshBtn;
    QTableWidget *m_memberTable;

    // 右侧详情区域
    QWidget *m_rightPanel;
    QVBoxLayout *m_rightLayout;
    
    // 会员基本信息区域
    QGroupBox *m_basicInfoGroup;
    QGridLayout *m_basicInfoLayout;
    QLabel *m_memberIdLabel;
    QLabel *m_memberNameLabel;
    QLabel *m_memberPhoneLabel;
    QLabel *m_memberLevelLabel;
    QLabel *m_discountRateLabel;
    QLabel *m_registerTimeLabel;

    // 会员账户信息区域
    QGroupBox *m_accountInfoGroup;
    QGridLayout *m_accountInfoLayout;
    QLabel *m_balanceLabel;
    QLabel *m_totalRechargedLabel;
    QLabel *m_accountCreateTimeLabel;
    QLabel *m_lastUpdateLabel;

    // 等级历史区域
    QGroupBox *m_levelHistoryGroup;
    QVBoxLayout *m_levelHistoryLayout;
    QTableWidget *m_levelHistoryTable;

    // 当前选中的会员ID
    int m_currentMemberId;

    // 会员数据缓存
    QVector<QMap<QString, QVariant>> m_memberListData;
};

#endif // MEMBERINFOPAGE_H